package com.ty.consumer;


import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class DirectConsumer {

    //定义一个队列 持久化 Q1
    @Bean
    public Queue Q1(){
        return QueueBuilder.durable("Q1").autoDelete().build();
    }

    //定义一个交换机Direct-ex  持久化 Q1
    @Bean
    public Exchange exchange(){
        return ExchangeBuilder.directExchange("Direct-ex").durable( true).build();
    }

    //队列和交换机的绑定关
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(Q1()).to(exchange()).with("rk02").noargs();
    }

    /*@RabbitListener(bindings=@QueueBinding(
            value = @Queue(name = "Q01", durable = "true",autoDelete = "false"),
            exchange =@Exchange(name = "Direct-ex",type= ExchangeTypes.DIRECT, durable = "true",autoDelete = "false"),
            key = "rk01"))*/


    @RabbitListener(queues = "Q1")
    public void consumer1(String msg){
        System.out.println("consumer1接收到消息："+msg);
    }

 /*  @RabbitListener(queues = "Q1")
    public void consumer2(String msg){
        System.out.println("consumer2接收到消息："+msg);
    }*/

}
